package com.td.evo.log.mutate;

import com.krakers.evo.log.EvolutionLogic;
import com.krakers.evo.obj.DNA;
import com.td.core.obj.TDMap;
import com.td.evo.log.TDEvolutionLogic;

public class TDMutatorLogic implements TDMap {

	private static final int S1 = BLD_X/2 * BLD_Y/2;
	
	public static void permutationPart1(DNA dna) {
		int g1 = EvolutionLogic.r.nextInt(S1);
		int g2 = EvolutionLogic.r.nextInt(S1);
		if(g1 != g2
				&& dna.getGene(g1) != 0
				&& dna.getGene(g2) != 0) {
			int temp = dna.getGene(g1);
			dna.setGene(g1, dna.getGene(g2));
			dna.setGene(g2, temp);
		}
	}
	
	public static void permutationPart2(DNA dna) {
		int g1 = S1 + EvolutionLogic.r.nextInt(S1);
		int g2 = S1 + EvolutionLogic.r.nextInt(S1);
		if(g1%2 == g2%2) {
			int temp = dna.getGene(g1);
			dna.setGene(g1, dna.getGene(g2));
			dna.setGene(g2, temp);
		}
	}
	
	public static void uniformPart1(DNA dna) {
		int g = EvolutionLogic.r.nextInt(S1);
		if(dna.getGene(g) != 0)
			dna.setGene(g, 1 + EvolutionLogic.r.nextInt(TDEvolutionLogic.TOWERS));
	}
}
